<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>上传控件</title>
</head>

<body>
<?php
function upload_file(){
	$targetFolder = '/Upload'; // Relative to the root
	if (!empty($_FILES)) {
		$tempFile = $_FILES['Filedata']['tmp_name'];
		
		// Validate the file type
		$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
		$fileParts = pathinfo($_FILES['Filedata']['name']);
		
		$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
		//$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
		$newfilename=date("YmdHis").mt_rand(10000,99999).'.'.$fileParts['extension'];
		$targetFile = rtrim($targetPath,'/') . '/' . $newfilename;
		
		if (in_array($fileParts['extension'],$fileTypes)) {
			move_uploaded_file($tempFile,$targetFile);
			$return=$relpath.trim($targetFolder,'/') . '/' . $newfilename;
			echo $return;
		} else {
			echo '';
		}
	}	
}
?>
<form method="post" action="#" enctype="multipart/form-data">
<input type="file" name="Filedata"  /><input type="text" name="aa" /><input type="submit" value="submit" />
</form>
</body>
</html>